<<<<<<< .mine
﻿#region using statements

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using NGen;
using NGen.Managers.GUI;
using NGen.Managers.GameObject;
using NGen.Managers.GameState;
using NGen.Managers.Input;
using NGen.Systems.StringAlarms;

using Nuclex.Input;

using Psych.GUILayouts;
using Psych.Misc;

#endregion
namespace Psych.States
{
    /// <summary>
    /// 	State of the game whenever the play screen is displayed
    /// </summary>
    public class GameStatePlay : GameState, IMouseListener, IKeyboardListener, IAlarmListener
    {
        #region local fields

        /// <summary>
        /// 	alarm system used for timed events
        /// </summary>
        private readonly AlarmSystem m_alarms = new AlarmSystem();

        /// <summary>
        /// 	the gui buttons
        /// </summary>
        private readonly GUIElementPlayStateLayout m_gui = new GUIElementPlayStateLayout();

        /// <summary>
        /// 	a saved reference to the alarm used to delay levels
        /// </summary>
        private AlarmObject m_levelAlarm;
        private GameLevel m_level;

        private bool m_shiftHeld;

        #endregion

        #region local methods

        /// <summary>
        /// 	Called whenever a gui button gets pressed. This is setup in the
        /// 	initialize function
        /// </summary>
        /// <param name = "guiEvent">a string to represent the event</param>
        private void _GUIEvent(string guiEvent)
        {
            switch (guiEvent)
            {
                case "startPressed":
                   
                    break;
            }
        }

       

        #region GameState implementation

        /// <summary>
        /// 	_Initialize this game state
        /// </summary>
        protected override void _Initialize()
        {
            
            //create the stats object and make it accessible as a service
            
            /*if (GameEngine.GetService<GameStats>() != null)
            {
                GameEngine.GameServices.RemoveService(typeof(GameStats));
            }
            GameEngine.GameServices.AddService(typeof(GameStats), stats);*/

            //provides a way for towers to access the list of enemies
           /* if (GameEngine.GetService<EnemyList>() != null)
            {
                GameEngine.GameServices.RemoveService(typeof(EnemyList));
            }
            GameEngine.GameServices.AddService(typeof(EnemyList), new EnemyList());*/

            //load the game world
            m_level = new GameLevel();
            //m_level = new GameLevel(GameEngine.GetService<GameOptions>().MapName);
            /*
            if (GameEngine.GetService<GameLevel>() != null)
            {
                GameEngine.GameServices.RemoveService(typeof(GameLevel));
            }
            GameEngine.GameServices.AddService(typeof(GameLevel), m_level);
            GameObjectEnemyBase.m_lWaypoint = m_level.GetEnemyPath();*/

            //load the gui
            GameEngine.GetService<IManagerGUI>().AddElement(m_gui);
            m_gui.GuiEvent += _GUIEvent; //listen for gui button presses

            //start the timer for the first wave
            m_levelAlarm = new AlarmObject(this, 5.0f, "nextLevel");
            m_alarms.Add(m_levelAlarm);
        }

        /// <summary>
        /// 	Perform all necessary actions to cleanup after this state exits
        /// </summary>
        protected override void _Cleanup()
        {
            GameEngine.GetService<IManagerGUI>().RemoveElement(m_gui);
            GameEngine.GetService<IManagerInput>().RemoveMouseListener(this);
            GameEngine.GetService<IManagerInput>().RemoveKeyboardListener(this);
            GameEngine.GetService<IManagerGameObjects>().DestroyAllGameObjects();
        }

        /// <summary>
        /// 	Called whenever this state is no longer the active state
        /// </summary>
        protected override void _OnFocusLost()
        {
            //this state shouldn't receive input while its not active
            GameEngine.GetService<IManagerInput>().RemoveKeyboardListener(this);
            GameEngine.GetService<IManagerInput>().RemoveMouseListener(this);
            GameEngine.GetService<IManagerGameObjects>().SkipUpdate = true;
        }

        /// <summary>
        /// 	Called whenever this state becomes the active state
        /// </summary>
        protected override void _OnFocusGained()
        {
            //this state should receive input again
            GameEngine.GetService<IManagerInput>().AddKeyboardListener(this);
            GameEngine.GetService<IManagerInput>().AddMouseListener(this);
            GameEngine.GetService<IManagerGameObjects>().SkipUpdate = false;
        }

        /// <summary>
        /// 	Update the game for this frame
        /// </summary>
        /// <param name = "p_gameTime">snapshot of timing values</param>
        protected override void _Update(GameTime p_gameTime)
        {
            m_alarms.Update(p_gameTime);
           /* m_gui.SetNextLevelTimer = ((int)m_levelAlarm.TimeRemaning).ToString();
            if (GameEngine.GetService<GameStats>().Lives <= 0)
            {
               GameEngine.GetService<IManagerGameState>().ChangeState(new GameStateGameOver());
            }*/
        }

        /// <summary>
        /// 	_Draw the game for this frame
        /// </summary>
        /// <param name = "p_gameTime">snapshot of timing values</param>
        protected override void _Draw(GameTime p_gameTime)
        {
            //clear the backbuffer
            GameEngine.GraphicsDeviceManager.GraphicsDevice.Clear(Color.Transparent);

            //initialize the backbuffer
            GameEngine.SpriteBatch.Begin();



            GameEngine.SpriteBatch.Draw( //draw the background
                m_level.LevelImage, new Vector2(12, 12), null, Color.White, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.01f);
            
           /* if (m_newTower != null)
            {
                m_newTower.WhilePlacing();
            }
            */
            //render to backbuffer
            GameEngine.SpriteBatch.End();
        }

        #endregion

        #region IMouseListener implementation

        /// <summary>
        /// 	Called whenever the mouse moves
        /// </summary>
        /// <param name = "x">x value of mouse position</param>
        /// <param name = "y">y value of mouse position</param>
        public void MouseMoved(float x, float y)
        {
            //if mouse is outside map bounds, move tower offscreen
            if (x >= 588 ||
               x < 12)
            {
                x = -1000;
            }
            if (y >= 588 ||
               y < 12)
            {
                y = -1000;
            }

        }

        /// <summary>
        /// 	Called whenever a mouse button is pressed
        /// </summary>
        /// <param name = "button">the button pressed</param>
        public void MousePressed(MouseButtons button)
        {
            switch (button)
            {
                case MouseButtons.Left:
                    {
                       
                    }
                    break;
                case MouseButtons.Right:
                 
                    break;
            }
        }

        /// <summary>
        /// 	Called whenever a mouse button is released
        /// </summary>
        /// <param name = "button">the button released</param>
        public void MouseReleased(MouseButtons button) { }

        /// <summary>
        /// 	Called whenever the mouse wheel is scrolled
        /// </summary>
        /// <param name = "ticks">the number of ticks scrolled</param>
        public void MouseWheelScroll(float ticks) { }

        #endregion

        #region IKeyboardListener implementation

        /// <summary>
        /// 	Called whenever a keyboard button is pressed
        /// </summary>
        /// <param name = "key">the key pressed</param>
        public void KeyPressed(Keys key)
        {
            switch (key)
            {
                case (Keys)16:
                    m_shiftHeld = true;
                    break;
                case Keys.U:
                  
                    break;
                case Keys.S:
                   
                    break;
                case Keys.Escape:
                    var state = new GameStatePause();
                    //this is just to have the pause state call the play state draw
                    state.ThrowDrawEvent += _Draw;
                    GameEngine.GetService<IManagerGameState>().PushState(state);
                    break;
            }
        }

        /// <summary>
        /// 	Called whenever a keyboard button is released
        /// </summary>
        /// <param name = "key">the key released</param>
        public void KeyReleased(Keys key)
        {
            if (key == (Keys)16)
            {
                m_shiftHeld = false;
            }
        }

        #endregion

        #region IAlarmListener implementation

        /// <summary>
        /// 	Called when an alarm event happens
        /// </summary>
        /// <param name = "message">the alarm message</param>
        public void OnAlarmEvent(string message)
        {
            switch (message)
            {
                case "nextLevel":
                    //increment the level
                    //GameEngine.GetService<GameStats>().Level += 1;

                    //create the enemy spawner for this level
                    /*var newSpawner = new GameObjectEnemySpawner
                    {
                        SkipDraw = true
                    };*/

                    //put the spawner in the objects manager
                    //GameEngine.GetService<IManagerGameObjects>().AddObject(newSpawner);

                    //load the spawner with enemies
                    /*for (var i = 0; i < 10; i++)
                    {
                        newSpawner.AddEnemy(new GameObjectEnemy());
                    }
                    */
                    //set the alarm for the next level to start in 20 seconds
                    m_levelAlarm = new AlarmObject(this, 20.0f, "nextLevel");

                    //add alarm to alarm system
                    m_alarms.Add(m_levelAlarm);
                    break;
            }
        }

        #endregion
    }
}
        #endregion=======
﻿#region using statements

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

using NGen;
using NGen.Managers.GUI;
using NGen.Managers.GameObject;
using NGen.Managers.GameState;
using NGen.Managers.Input;
using NGen.Systems.StringAlarms;

using Nuclex.Input;

using Psych.GUILayouts;


#endregion
namespace Psych.States
{
    /// <summary>
    /// 	State of the game whenever the play screen is displayed
    /// </summary>
    public class GameStatePlay : GameState, IMouseListener, IKeyboardListener, IAlarmListener
    {
        #region local fields

        /// <summary>
        /// 	alarm system used for timed events
        /// </summary>
        private readonly AlarmSystem m_alarms = new AlarmSystem();

        /// <summary>
        /// 	the gui buttons
        /// </summary>
        private readonly GUIElementPlayStateLayout m_gui = new GUIElementPlayStateLayout();

        /// <summary>
        /// 	a saved reference to the alarm used to delay levels
        /// </summary>
        private AlarmObject m_levelAlarm;


        private bool m_shiftHeld;

        #endregion

        #region local methods

        /// <summary>
        /// 	Called whenever a gui button gets pressed. This is setup in the
        /// 	initialize function
        /// </summary>
        /// <param name = "guiEvent">a string to represent the event</param>
        private void _GUIEvent(string guiEvent)
        {
            switch (guiEvent)
            {
                case "startPressed":
                   
                    break;
            }
        }

       

        #region GameState implementation

        /// <summary>
        /// 	_Initialize this game state
        /// </summary>
        protected override void _Initialize()
        {
            
            //create the stats object and make it accessible as a service
            
            /*if (GameEngine.GetService<GameStats>() != null)
            {
                GameEngine.GameServices.RemoveService(typeof(GameStats));
            }
            GameEngine.GameServices.AddService(typeof(GameStats), stats);*/

            //provides a way for towers to access the list of enemies
           /* if (GameEngine.GetService<EnemyList>() != null)
            {
                GameEngine.GameServices.RemoveService(typeof(EnemyList));
            }
            GameEngine.GameServices.AddService(typeof(EnemyList), new EnemyList());*/

            //load the game world
           /* m_level = new GameLevel(GameEngine.GetService<GameOptions>().MapName);

            if (GameEngine.GetService<GameLevel>() != null)
            {
                GameEngine.GameServices.RemoveService(typeof(GameLevel));
            }
            GameEngine.GameServices.AddService(typeof(GameLevel), m_level);
            GameObjectEnemyBase.m_lWaypoint = m_level.GetEnemyPath();*/

            //load the gui
            GameEngine.GetService<IManagerGUI>().AddElement(m_gui);
            m_gui.GuiEvent += _GUIEvent; //listen for gui button presses

            //start the timer for the first wave
            m_levelAlarm = new AlarmObject(this, 5.0f, "nextLevel");
            m_alarms.Add(m_levelAlarm);
        }

        /// <summary>
        /// 	Perform all necessary actions to cleanup after this state exits
        /// </summary>
        protected override void _Cleanup()
        {
            GameEngine.GetService<IManagerGUI>().RemoveElement(m_gui);
            GameEngine.GetService<IManagerInput>().RemoveMouseListener(this);
            GameEngine.GetService<IManagerInput>().RemoveKeyboardListener(this);
            GameEngine.GetService<IManagerGameObjects>().DestroyAllGameObjects();
        }

        /// <summary>
        /// 	Called whenever this state is no longer the active state
        /// </summary>
        protected override void _OnFocusLost()
        {
            //this state shouldn't receive input while its not active
            GameEngine.GetService<IManagerInput>().RemoveKeyboardListener(this);
            GameEngine.GetService<IManagerInput>().RemoveMouseListener(this);
            GameEngine.GetService<IManagerGameObjects>().SkipUpdate = true;
        }

        /// <summary>
        /// 	Called whenever this state becomes the active state
        /// </summary>
        protected override void _OnFocusGained()
        {
            //this state should receive input again
            GameEngine.GetService<IManagerInput>().AddKeyboardListener(this);
            GameEngine.GetService<IManagerInput>().AddMouseListener(this);
            GameEngine.GetService<IManagerGameObjects>().SkipUpdate = false;
        }

        /// <summary>
        /// 	Update the game for this frame
        /// </summary>
        /// <param name = "p_gameTime">snapshot of timing values</param>
        protected override void _Update(GameTime p_gameTime)
        {
            m_alarms.Update(p_gameTime);
           /* m_gui.SetNextLevelTimer = ((int)m_levelAlarm.TimeRemaning).ToString();
            if (GameEngine.GetService<GameStats>().Lives <= 0)
            {
               GameEngine.GetService<IManagerGameState>().ChangeState(new GameStateGameOver());
            }*/
        }

        /// <summary>
        /// 	_Draw the game for this frame
        /// </summary>
        /// <param name = "p_gameTime">snapshot of timing values</param>
        protected override void _Draw(GameTime p_gameTime)
        {
            //clear the backbuffer
            GameEngine.GraphicsDeviceManager.GraphicsDevice.Clear(Color.Transparent);

            //initialize the backbuffer
            GameEngine.SpriteBatch.Begin();

/*

            GameEngine.SpriteBatch.Draw( //draw the background
                m_level.LevelImage, new Vector2(12, 12), null, Color.White, 0.0f, Vector2.Zero, Vector2.One, SpriteEffects.None, 0.01f);

            if (m_newTower != null)
            {
                m_newTower.WhilePlacing();
            }
            */
            //render to backbuffer
            GameEngine.SpriteBatch.End();
        }

        #endregion

        #region IMouseListener implementation

        /// <summary>
        /// 	Called whenever the mouse moves
        /// </summary>
        /// <param name = "x">x value of mouse position</param>
        /// <param name = "y">y value of mouse position</param>
        public void MouseMoved(float x, float y)
        {
            //if mouse is outside map bounds, move tower offscreen
            if (x >= 588 ||
               x < 12)
            {
                x = -1000;
            }
            if (y >= 588 ||
               y < 12)
            {
                y = -1000;
            }

        }

        /// <summary>
        /// 	Called whenever a mouse button is pressed
        /// </summary>
        /// <param name = "button">the button pressed</param>
        public void MousePressed(MouseButtons button)
        {
            switch (button)
            {
                case MouseButtons.Left:
                    {
                       
                    }
                    break;
                case MouseButtons.Right:
                 
                    break;
            }
        }

        /// <summary>
        /// 	Called whenever a mouse button is released
        /// </summary>
        /// <param name = "button">the button released</param>
        public void MouseReleased(MouseButtons button) { }

        /// <summary>
        /// 	Called whenever the mouse wheel is scrolled
        /// </summary>
        /// <param name = "ticks">the number of ticks scrolled</param>
        public void MouseWheelScroll(float ticks) { }

        #endregion

        #region IKeyboardListener implementation

        /// <summary>
        /// 	Called whenever a keyboard button is pressed
        /// </summary>
        /// <param name = "key">the key pressed</param>
        public void KeyPressed(Keys key)
        {
            switch (key)
            {
                case (Keys)16:
                    m_shiftHeld = true;
                    break;
                case Keys.U:
                  
                    break;
                case Keys.S:
                   
                    break;
                case Keys.Escape:
                    var state = new GameStatePause();
                    //this is just to have the pause state call the play state draw
                    state.ThrowDrawEvent += _Draw;
                    GameEngine.GetService<IManagerGameState>().PushState(state);
                    break;
            }
        }

        /// <summary>
        /// 	Called whenever a keyboard button is released
        /// </summary>
        /// <param name = "key">the key released</param>
        public void KeyReleased(Keys key)
        {
            if (key == (Keys)16)
            {
                m_shiftHeld = false;
            }
        }

        #endregion

        #region IAlarmListener implementation

        /// <summary>
        /// 	Called when an alarm event happens
        /// </summary>
        /// <param name = "message">the alarm message</param>
        public void OnAlarmEvent(string message)
        {
            switch (message)
            {
                case "nextLevel":
                    //increment the level
                    //GameEngine.GetService<GameStats>().Level += 1;

                    //create the enemy spawner for this level
                    /*var newSpawner = new GameObjectEnemySpawner
                    {
                        SkipDraw = true
                    };*/

                    //put the spawner in the objects manager
                    //GameEngine.GetService<IManagerGameObjects>().AddObject(newSpawner);

                    //load the spawner with enemies
                    /*for (var i = 0; i < 10; i++)
                    {
                        newSpawner.AddEnemy(new GameObjectEnemy());
                    }
                    */
                    //set the alarm for the next level to start in 20 seconds
                    m_levelAlarm = new AlarmObject(this, 20.0f, "nextLevel");

                    //add alarm to alarm system
                    m_alarms.Add(m_levelAlarm);
                    break;
            }
        }

        #endregion
    }
}
        #endregion>>>>>>> .r47
